
Uec3.NotepadWindow = Ext.extend(Ext.app.Module, {
   id: 'notepad',
   type: 'common/notepad',
   num: 1,
   
   
   /**
    * Initialize this module.
    * This function is called at startup (page load/refresh).
    */
   init : function(initParams){
   		
   },
	 

	/**
	 * Create this modules window here.
	 */
   createWindow : function(){
       var desktop = this.app.getDesktop();
    
    	 var tarea = new Ext.form.TextArea({
				  width:498,
				  height:320,
				  name:'text',
				  preventScrollbars:true,
					hideLabel : true,
					anchor:'100%',
					viewValue: function(){
				   	 Ext.Ajax.request({
				    		url: Uec3.App.Constants.homeUrl+"/huarui/notepad/view.do",
				    		params: {
				    			  userId: Uec3.App.Constants.userId
				    		},
				    		success: function(o){
				    			 eval("var p="+o.responseText);
				    			 tarea.setValue(p.text);
				    			 tarea.setDisabled(true);
				    		},
				    		failure: function(){
				    			 Ext.MessageBox.alert('提示','查询记事本资料发生错误!');
				    		},
				    		scope: tarea
				    	});
				  },
					saveValue: function(){
						 alert("saveValue");
				   	 Ext.Ajax.request({
				    		url: Uec3.App.Constants.homeUrl+"/huarui/notepad/save.do",
				    		params: {
				    			  userId: Uec3.App.Constants.userId,
				    			  text: tarea.getValue()
				    		},
				    		success: function(o){
				    			 tarea.setDisabled(true);
				    			 Ext.MessageBox.alert('提示','资料保存成功');
				    		},
				    		failure: function(){
				    			 Ext.MessageBox.alert('提示','资料保存失败!');
				    		},
				    		scope: tarea
				    	});
				  },
					clearValue:function(){
				   	 Ext.Msg.confirm('确认', '确定清除资料', function(btn){
				   	 	 if(btn=='yes'){
					   	 	 this.setValue("");
						   	 this.saveValue();
						   	}
				   	  },tarea);
				  },
				  editValue: function(){
				   	 tarea.setDisabled(false);
				  }
				  
			 });

    	 var panel = new Ext.FormPanel({
					frame : true,
					border: true,
					autoHeight:true,
					autoWidth:true,
					url:'',
					
					items :[
						tarea
					],
					tbar: [
             {
                text: '保存',
                tooltip: '保存数据',
                iconCls: 'demo-grid-add',
                handler:tarea.saveValue,
                scope:this
							},
             '-',
             {
                text: '清除',
                tooltip: '保存数据',
                iconCls: 'demo-grid-remove',
                handler:tarea.clearValue,
                scope:this
             },
             '-',
             {
                text:'编辑',
                tooltip:'编辑数据',
                iconCls:'demo-grid-option',
                handler:tarea.editValue,
                scope:this
							}
          ]
    	 });
    	
       var win = desktop.createWindow({
          id: 'notepad'+(this.num++),
          title: '记事本',
          width: 500,
          height: 400,
          iconCls: 'acc-icon',
          shim: false,
          animCollapse: false,
          constrainHeader: true,
          maximizable: true,
          taskbuttonTooltip: "我的记事本",
          layout: "fit",
          tools: [
             {
                id:'refresh',
                handler: Ext.emptyFn,
                scope: this
             }
           ],
           items:[panel]
       });

		   win.on("bodyresize",function(){
		       tarea.setHeight(win.getHeight()-90);
		       this.setLookupValue({'name':'test','pyCode':'00122','id':'1'},win);
				},this);
      
       var area=win.items.get(0).getForm().findField("text");
       area.viewValue();
       win.show();
      
   }
});